package com.example.javaairportflightanalysis.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.example.javaairportflightanalysis.common.ApiRestResponse;
import com.example.javaairportflightanalysis.domin.userpojo.Role;
import com.example.javaairportflightanalysis.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @SaCheckPermission(value = "ROLE_SELECT", orRole = "ROLE_ADMIN")
    @GetMapping("/selectAllRole")
    public ApiRestResponse selectAllRole(Integer id){
        return ApiRestResponse.success(roleService.selectById(id));
    }

    @GetMapping("/findAllRole")
    @SaCheckPermission(value = "ROLE_SELECT", orRole = "ROLE_ADMIN")
    public ApiRestResponse findAllRole(){
        return ApiRestResponse.success(roleService.findAllRole());
    }

    @PostMapping("/addRole")
    @SaCheckPermission(value = "ROLE_ADD", orRole = "ROLE_ADMIN")
    public ApiRestResponse addRole(@RequestBody Role role){
        roleService.addRole(role);
        return ApiRestResponse.success();
    }

    @GetMapping("/deleteRole")
    @SaCheckPermission(value = "ROLE_DELETE", orRole = "ROLE_ADMIN")
    public ApiRestResponse deleteRole(@RequestParam Integer id){
        roleService.deleteRole(id);
        return ApiRestResponse.success();
    }

    @PostMapping("/updateRole")
    @SaCheckPermission(value = "ROLE_SELECT", orRole = "ROLE_ADMIN")
    public ApiRestResponse updateRole(@RequestBody Role role){
        roleService.updateRole(role);
        return ApiRestResponse.success();
    }

}
